﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Itfort.Web;

namespace WanPiJie.WebSite.MyBaby
{
	public partial class AddGrowthRecord_f : PageMustLogin
	{
		protected string from;
		protected bool isFirst;
		protected Baby Baby { get; set; }

		protected void Page_Load(object sender, EventArgs e)
		{
			from = Request.QueryString["from"];
			if (from != null) from = from.ToLower();
			int babyId = Request.ToInt32("babyId");
			Baby = WpjSf.BabyService.GetBaby(babyId);
			if (Baby == null)
			{
				throw new Exception("错误的参数");
			}
			this.isFirst = !WpjSf.GrowthRecordService.ExistsGrowthRecords(babyId);
		}

		protected void BtnOK_Click(object sender, EventArgs e)
		{
			double height = Request.ToDouble("f_Height");
			double weight = Request.ToDouble("f_Weight");
			double headSize = Request.ToDouble("f_HeadSize");
			double chestSize = Request.ToDouble("f_ChestSize");
			DateTime surveyDate = Request.ToDateTime("f_SurveyDate");

			var growthRecord = WpjSf.GrowthRecordService.AddGrowthRecord(this.Baby.Id, surveyDate, height, weight, headSize, chestSize);
			this.Result.Success();

			if (from == "addbaby")
			{
				Response.Redirect("SendWeibo-f.aspx");
			}
		}
	}
}